﻿using ContractMeow.Api.Dtos.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ContractMeow.Api.Dtos.Message
{
    public sealed class Body
    {
		string[] _urlsStringified;
		List<Uri> _urls = new List<Uri>();

        [JsonProperty( "parsed" )]
        public String Parsed { get; set; }
        [JsonProperty( "plain" )]
        public String Plain { get; set; }
        [JsonProperty( "rich" )]
        public String Rich { get; set; }

		/// <summary>
		/// This property its only purpose is to translate stringified Uris into valid Uri.
		/// This property is for internal use only.
		/// </summary>
		/// <value>The urls stringified.</value>
	    [JsonProperty("urls")]
	    internal string[] UrlsStringified
	    {
		    get { return _urlsStringified; }
		    set
		    {
			    _urlsStringified = value;
			    if (_urlsStringified != null) {
				    _urls.Clear();
				    _urls.AddRange(_urlsStringified.Where(s => s.IsUri()).Select(s => s.ToUri()));
			    }
		    }
	    }

		/// <summary>
		/// Gets the urls.
		/// This is the method used everywhere in the application
		/// </summary>
		/// <value>The urls.</value>
	    public IList<Uri> Urls
	    {
		    get { return _urls; }
	    }
    }
}